package com.iap.client.mediator
{
	import com.iap.client.event.MainEvent;
	import com.iap.client.view.MainMenuView;
	import com.iap.client.view.control.AdminButton;
	import com.iap.client.view.control.ClientButton;
	import com.iap.client.view.control.FavoriteReportButton;
	import com.iap.client.view.control.HomeButton;
	
	import flash.events.MouseEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	public class MainMenuMediator extends Mediator
	{
		[Inject]
		public var view:MainMenuView;

		override public function onRegister():void
		{
			addViewListener(MouseEvent.CLICK, handleMouseClick);
		}

		private function handleMouseClick(evt:MouseEvent):void
		{
			var propertyName:String = "name";
			var btnName:String = "";
			if(evt.target.hasOwnProperty(propertyName))
			{
				btnName = evt.target[propertyName];
			}
			onMenuSelected(btnName);
		}

		private function onMenuSelected(menuName:String):void
		{
			switch(menuName)
			{
				case ClientButton.NAME:
				{
					dispatch(new MainEvent(MainEvent.SELECT_CLIENT));
					break;
				}
				case AdminButton.NAME:
				{
					dispatch(new MainEvent(MainEvent.SELECT_ADMIN));
					break;
				}
				case HomeButton.NAME:
				{
					dispatch(new MainEvent(MainEvent.SELECT_HOME));
					break;
				}
				case FavoriteReportButton.NAME:
				{
					dispatch(new MainEvent(MainEvent.SELECT_REPORT));
					break;
				}
			}
		}
	}
}